package utils;


import java.awt.Image;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;

public class ImageUtil {
    public static BufferedImage resizeImage(BufferedImage originalImage, int targetWidth, int targetHeight) throws IOException {
        Image resultingImage = originalImage.getScaledInstance(targetWidth, targetHeight, Image.SCALE_AREA_AVERAGING);
        BufferedImage outputImage = new BufferedImage(targetWidth, targetHeight, BufferedImage.TYPE_INT_RGB);
        outputImage.getGraphics().drawImage(resultingImage, 0, 0, null);
        return outputImage;
    }
    
    public static int getPicWidth(File file) throws IOException {
        BufferedImage srcImage= ImageIO.read(file);
        return srcImage.getWidth();
    }
    
    public static int getPicHeight(File file) throws IOException {
        BufferedImage srcImage= ImageIO.read(file);
        return srcImage.getHeight();
    }
}
